#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f3f
const int N=2e5+1;
const int M=2e3+1;
inline int read(){
    int f=1,x=0;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-'0';c=getchar();}
    return f*x;
}
int T,n,dp[2][M][M],a[N],maxx,ans;//like zooma
void dfs(int dep,int col1,int col2,int pt){
    if(dep>n){
        ans=max(ans,pt);
        return;
    }
    dfs(dep+1,a[dep+1],col2,pt+(col1==a[dep+1])*col1);
    dfs(dep+1,col1,a[dep+1],pt+(col2==a[dep+1])*col2);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--){
        n=read();ans=0;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)a[i]=read();
        dfs(0,0,0,0);
        printf("%d\n",ans);
    }
}
